home *** CD-ROM | disk | FTP | other *** search
/ Hacker's Secrets 4 / Hacker's Secrets 4.iso / internet / sendfake.c < prev    next >
C/C++ Source or Header  |  1996-04-26  |  3KB  |  143 lines

  1. /* *************************************************************************
  2.                 SENDFAKE.C
  3.  
  4.   Author: asm@quantum.syspac.com
  5.  
  6.   This program reads a file with the body of your forged mail and sends
  7.   it to a given address.  You must edit a file and put the contents of
  8.   your mail in first.
  9.  
  10.   To compile: gcc -o sendfake sendfake.c   (don't worry about warning errors)
  11.  
  12.   usage: sendfake   (You must have the text of the fake mail in a file!)  
  13.   
  14.   *********************************************************************** */
  15.  
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <errno.h>
  19. #include <signal.h>
  20. #include <sys/types.h>
  21. #include <sys/socket.h>
  22. #include <netinet/in.h>
  23. #include <netdb.h>
  24.  
  25. #define MAXLEN 256
  26.  
  27. int s;
  28.  
  29. int call_socket(char *hostname)
  30. {
  31.   struct sockaddr_in sa;
  32.   struct hostent     *hp;
  33.   int    a, s;
  34.  
  35.   if ((hp=gethostbyname(hostname))==NULL) return(-1);
  36.   bzero(&sa, sizeof(sa));
  37.   bcopy(hp->h_addr, (char *)&sa.sin_addr, hp->h_length);
  38.   sa.sin_family = hp->h_addrtype;
  39.   sa.sin_port = htons((u_short)25);
  40.  
  41.   if((s=socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0)
  42.     return(-1);
  43.   if(connect(s, &sa, sizeof(sa)) < 0) {
  44.     close(s);
  45.     return(-1);
  46.   }
  47.   return(s);
  48. }
  49.  
  50. int readln(char *buf)
  51. {
  52.   int to=0;
  53.   char c;
  54.  
  55.   do {
  56.     if(read(s, &c, 1)<1)
  57.       return(0);
  58.     if((c >= ' ') || (c <= 126))
  59.       if(to<MAXLEN-1)
  60.         buf[to++] = c;
  61.   } while (c != '\n');
  62.  
  63.   buf[to] = '\0';
  64.   return(1);
  65. }
  66.  
  67. void writeln(char *buf)
  68. {
  69.   write(s, buf, strlen(buf));
  70.   write(s, "\n",1);
  71. }
  72.  
  73. void input(char *msg,char *pt)
  74. {
  75.    printf("%s: ",msg);
  76.    gets(pt);
  77. }
  78.  
  79. int main(void)
  80. {
  81.   char hostn[20];
  82.   char from[40];
  83.   char to[40];
  84.   char name[40];
  85.   char subject[60];
  86.   char passw[20];
  87.   char str[MAXLEN];
  88.   char buf[MAXLEN];
  89.   FILE *fp;
  90.  
  91.   printf("\n");
  92.   printf("Welcome to sendfake!  The BEST fake/anon mailer there is!\n");
  93.   printf("12-27-1995, asm@quantum.syspac.com\n");
  94.   printf("\n"); 
  95.   input("Host to fake mail from",hostn);
  96.   if((s=call_socket(hostn)) <0) {
  97.     perror("Connection error");
  98.     exit(1);
  99.   }
  100.   readln(buf);
  101.   gethostname(hostn,20);
  102.   sprintf(str, "HELO %s", hostn);
  103.   writeln(str);
  104.   readln(buf);
  105.   input("Fake email address fakemail is FROM",from);
  106.   sprintf(str, "MAIL FROM: <%s>",from);
  107.   writeln(str);
  108.   readln(buf);
  109.   do {
  110.     input("Send fake mail TO",to);
  111.     sprintf(str, "RCPT TO: <%s>",to);
  112.     writeln(str);
  113.     readln(buf);
  114.     *(buf+3) = 0;
  115.     if(atoi(buf) == 250) break; else printf("%s",buf+4);
  116.   } while(1);
  117.   input("Name of lamer getting the fake mail",name);
  118.   input("Subject of fake mail",subject);
  119.   writeln("DATA");
  120.   sprintf(str,"To: %s <%s>",name,to);
  121.   writeln(str);
  122.   if(strlen(subject)) {
  123.     sprintf(str, "Subject: %s", subject);
  124.     writeln(str);
  125.   }
  126.   do {
  127.     input("File to read and include in fake mail",str);
  128.     if(!strlen(str)) {
  129.       close(s);
  130.       exit(1);
  131.     }
  132.     if((fp = fopen(str,"rt")) == NULL) printf("Could not find file %s\n", 
  133. str);
  134.     else break;
  135.   } while(1);
  136.   while(fgets(str,MAXLEN,fp)) write(s, str, strlen(str));
  137.   writeln("\n.\n");
  138.   readln(buf);
  139.   writeln("QUIT\n");
  140.   printf("Sent!!!\n");
  141.   close(s);
  142. }
  143.